<template>
	<view class="solutionDetailPage">
		<view class="detailContent">
			<view class="solutionDetailTitle">{{info.name}}</view>
			<view class="solutionDetailInfo">
				<u-parse style="width: 100%;word-break: break-all;" :content="info.content"></u-parse>
			</view>
		</view>
		<view class="solutionOperate">
			<view class="operateItem specialItem" @click="showShareContent=true">
				<u--image src="/static/solution/1.png" shape="square" mode="aspectFill" width="32rpx" height="32rpx">
				</u--image>
				<view class="text">分享</view>
			</view>
			<view class="operateItem specialItem" @click="doStar(2)">
				<u--image src="/static/solution/2.png" shape="square" mode="aspectFill" width="32rpx" height="32rpx"
					v-if="!info.isCollection">
				</u--image>
				<u--image src="/static/solution/22.png" shape="square" mode="aspectFill" width="32rpx" height="32rpx"
					v-else>
				</u--image>
				<view class="text">收藏</view>
			</view>
			<view class="operateItem" @click="doStar(1)">
				<u--image src="/static/solution/3.png" shape="square" mode="aspectFill" width="32rpx" height="32rpx"
					v-if="!info.isThumbsUp">
				</u--image>
				<u--image src="/static/solution/33.png" shape="square" mode="aspectFill" width="32rpx" height="32rpx"
					v-else>
				</u--image>
				<view class="text">赞</view>
			</view>
		</view>
		<u-popup :show="showShareContent" :round="10" mode="bottom" @close="close" @open="open">
			<view class="shareContent">
				<view class="title">分享到</view>
				<view class="shareInfo">
					<button class="shareItem" open-type="share">
						<u--image src="/static/share/2.png" radius="50%" shape="square" mode="aspectFill"
							width="106rpx" height="106rpx">
						</u--image>
						<view class="itemTitle">微信</view>
					</button>
					<button class="shareItem" @click="goDiscuss">
						<u--image src="/static/share/1.png" radius="50%" shape="square" mode="aspectFill"
							width="106rpx" height="106rpx">
						</u--image>
						<view class="itemTitle">社区内发帖</view>
					</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				userId: "",
				showShareContent: false,
			}
		},
		onLoad(option) {
			uni.getStorage({
				key: "userInfo",
				success: (userInfo) => {
					this.userId = userInfo.data.id;
					this.info.id = option.id;
					this.initData()
				}
			})
		},
		methods: {
			close() {
				this.showShareContent = false;
			},
			open() {
				this.showShareContent = true;
			},
			goDiscuss() {
				uni.setStorage({
					key: "shareData",
					data: {
						id: this.info.id,
						types: "2"
					},
					success: () => {
						uni.switchTab({
							url: "/pages/discuss/discuss"
						})
					}
				})
			},
			initData() {
				this.$request.get(this.$api.getNewsDetail, {
					id: this.info.id,
					userId: this.userId
				}).then(res => {
					uni.hideLoading()
					this.info = res.result
					getCurrentPages().forEach(item => {
						if (item.$vm.updateArticle) {
							item.$vm.updateArticle(this.info)
						}
					})
					
				})
			},
			doStar(type) {
				let url = ""
				if ((type == 1 && this.info.isThumbsUp) || (type == 2 && this.info.isCollection)) {
					url = this.$api.cancelStar
				} else {
					url = this.$api.doStar
				}
				this.$request.get(url, {
					id: this.info.id,
					userId: this.userId,
					type: type
				}).then(res => {
					if (type == 1 && !this.info.isThumbsUp) {
						this.info.isThumbsUp = true;
						uni.showToast({
							icon: "success",
							title: "点赞成功",
							duration: 3000
						})
						return;
					}
					if (type == 2 && !this.info.isCollection) {
						this.info.isCollection = true;
						uni.showToast({
							icon: "success",
							title: "收藏成功",
							duration: 3000
						})
						return;
					}
					if (type == 1 && this.info.isThumbsUp) {
						this.info.isThumbsUp = false;
						uni.showToast({
							icon: "success",
							title: "取消点赞成功",
							duration: 3000
						})
						return;
					}
					if (type == 2 && this.info.isCollection) {
						this.info.isCollection = false;
						uni.showToast({
							icon: "success",
							title: "取消收藏成功",
							duration: 3000
						})
						return;
					}
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss">
	.solutionDetailPage {
		background-color: #fff;

		.detailContent {
			display: inline-block;
			position: relative;
			height: calc(100vh - 120rpx);
			width: 100vw;
			overflow-x: hidden;
			overflow-y: auto;
		}

		.solutionDetailTitle {
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 600;
			color: #333333;
			font-size: 36rpx;
			padding: 0 40rpx;
		}

		.solutionDetailInfo {
			padding: 20rpx 40rpx 40rpx;
			color: #666666;
			font-size: 28rpx;
		}

		.solutionOperate {
			display: flex;
			justify-content: space-around;
			flex-wrap: nowrap;
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100vw;
			height: 120rpx;
			box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.04);
			background: #ffffff;
			padding-bottom: 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.operateItem {
				display: flex;
				justify-content: center;
				flex-wrap: nowrap;
				align-items: center;
				font-size: 26rpx;
				width: calc(100% / 3);
				position: relative;

				.text {
					padding-left: 8rpx;
					display: inline-block;
				}
			}

			.specialItem {
				&:after {
					content: "";
					display: inline-block;
					height: 32rpx;
					width: 1px;
					background-color: #BDBDBDFF;
					position: absolute;
					right: 0;
					top: calc(50% - 16rpx);
				}
			}
		}

		.shareContent {
			height: 400rpx;

			.title {
				height: 100rpx;
				border-bottom: 1rpx solid #eeeeee;
				text-align: center;
				line-height: 100rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}

			.shareInfo {
				display: flex;
				justify-content: space-around;
				flex-wrap: nowrap;
				padding-top: 40rpx;

				.shareItem {
					display: flex;
					flex-direction: column;
					align-items: center;

					.itemTitle {
						padding-top: 30rpx;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}
			}
		}
	}
</style>
